var vm_zhuanjiazhuanyi = new Vue({
    el: "#zhuanjiazhuanyi",
    data: {
        id:$("#id").val(),      //传值单位ID，用于左侧查询专家
        oldid:$("#oldid").val(),      //传值旧单位ID，用于左侧查询专家
        deptid:$("#deptid").val(),      //当前登录的新单位ID
        olddeptid: $("#olddeptid").val(),		// 当前登录的旧单位ID

        deptlist: [],// 单位列表custom
        zhuanjialist: [],//专家列表custom

        zhuanyizhuanjialist:[],

        //专家查询用字段
        xingming: '',

        //单位查询用字段
        jigoumingcheng: '',
        jigoudaima: '',

    },
    created: function () {
        var _this = this;

        _this.bindZhuanjiaList();
        _this.bindDeptList();

    },
    methods: {

        // 根据单位ID查询下级单位
        bindDeptList: function () {
            var _this = this;

            var dept_layer = layer.open({type: 3});
            $.post('/system/deptdetail/customlist', {
                parentid: _this.olddeptid,
                jigoumingcheng: _this.jigoumingcheng,
                jigoudaima: _this.jigoudaima,
                rdm: Math.random()
            }, function (ppData) {
                layer.close(dept_layer);

                if (ppData != null) {
                    var data = ppData;
                    _this.deptlist = data;
                }
            }, "json");
        },

        bindZhuanjiaList:function(){
            var _this = this;

            var zhuanjia_layer = layer.open({type:3});
            $.post('/system/zhuanjia/customlist', {
                deptid : _this.id,
                xingming : _this.xingming,
                pageindex : 1,
                pagesize : 999,
                rdm : Math.random()
            },function(ppData) {
                layer.close(zhuanjia_layer);

                if (ppData != null) {
                    var data = ppData.resultContent;

                    _this.zhuanjialist = data.zhuanjialist;

                }
            },"json");
        },

        zhuanyi:function(ppDeptId){
            var _this = this;

            var zhuanjiaids = '';

            var chk_value =[];
            $('input[name="zhuanjia_ckb"]:checked').each(function(){
                chk_value.push($(this).val());
            });
            if (chk_value.length==0){
                layer.alert('您还没有选择任何专家！');
            }else{
                for(var i=0;i<chk_value.length;i++){
                    zhuanjiaids = zhuanjiaids+chk_value[i]+",";
                }
            }

            var zhuanjia_layer = layer.open({type: 3});
            $.post('/system/deptzhuanjia/zhuanyi', {
                zhuanjiaids:zhuanjiaids,
                deptid:ppDeptId,
                rdm: Math.random()
            }, function (ppData) {
                layer.close(zhuanjia_layer);
                if (ppData != null) {

                    if (ppData.result == "1") {
                        layer.open({
                            time: 1000,
                            btn: [],
                            content: ppData.resultContent,
                        });

                        _this.refresh();

                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },

        refresh:function(){
            var _this = this;
            $('input[name="zhuanjia_ckb"]').prop("checked",false);
            _this.bindZhuanjiaList();
        }

    }
})
